<?php

namespace app\admin\controller;
use app\admin\model\SystemManager;
use app\model\Goods;
use think\Controller;
use think\Db;

class Index extends Basic
{

    /**
     * 初始化-继承
     * @author jihaichuan
     */
    public function _initialize()
    {
        // 继承
        parent::_initialize();
    }



    public function index()
    {
        echo '小程序（北京）科技有限公司 技术支持';
    }


    /**
     * 上传图片
     * @author jihaichuan
     */
    public function upload_img()
    {
        // 上传的文件夹
        $folder = input('folder');
        if (!$folder) {
            json_fail([
                'status' => -10,
                'msg' => '请设置上传目录'
            ]);
        }

        // 上传图片的字段
        //$field = input('field', 'img');
        $file = request()->file('file');
        if (!$file) {
            json_fail([
                'status' => -11,
                'msg' => '请上传文件'
            ]);
        }

        // 上传单张图片还是多种图片
        $type = input('type', 'single');
        if (!in_array($type, ['single', 'multi'])) {
            json_fail([
                'status' => -12,
                'msg' => 'type参数值不对'
            ]);
        }

        // 判断是否上传图片
        if ($type == 'single') {
            $img = $this->upload_single_img($file, $folder);
        } else {
            $img = $this->upload_multi_img($file, $folder);
        }

        // 返回上传的图片
        json_success($img);
    }



    /**
     * User: Administrator
     * Date: 2018/9/6
     * Time: 17:34
     * 角色下载视频
     */
    public function user_download()
    {
        $token = input('post.token');
        if (!$token) {
            json_fail(data('-5', 'token不能为空!'));
        }
        $user_id = decode(input('post.user_id'));
        if (!$user_id) {
            json_fail(data('-5', '用户ID不能为空!'));
        }
        $SysteMmanager = new SystemManager();
       $identity = $SysteMmanager->where('id',$user_id)->value('identity');
       if ($identity)
       {
           json_success($identity);
       }else{
           json_success([]);
       }


    }
}
